package com.cy.shiro.util;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Collection;
import java.util.List;

@Data
@EqualsAndHashCode
public class ResultObject<T> {

    private Integer status;
    private String message;
    private T data;



    public ResultObject(Integer status, String message) {
        this.status = status;
        this.message = message;
    }

    public ResultObject(Integer status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public String toJosn(){
        T t = this.getData();
        if(t instanceof List || t instanceof Collection){
            return JSONObject.toJSONString(this, SerializerFeature.WriteNullListAsEmpty);
        } else {
            return JSONObject.toJSONString(this, SerializerFeature.WriteMapNullValue);
        }
    }
}
